Subject: Re: Bugs, Bugs, Bugs...
From: Paul Reece <[email-masked]>
To: Nigel Hughes <[email-masked]>
Cc: [email-masked]
Date: Fri, 17 Jun 1994 08:51:59 +1000 (EST)

On Thu, 16 Jun 1994, Nigel Hughes wrote:

>  Hello everybody,
> 		I decided to try and write some of my more useful Blitz functions
> into a library yesterday, so I sit down, read the various bits on library writing, I can
> already code in 68k (written a full game in it 8) so I think no problems! I was wrong!
> 
> I seem to be upsetting blitz with the following routines! They actualy work as far as
> functionality goes, but after using them I get a recoverable alert 0100 000C, which
> is I think, exec saying it has a knackered memory list! Just as a control the second
> function PCFSize (_pcfsize) which quite simply returns the length of a file, causes
> the same things as the very slightly more complex CachePCF (_cachepcf). 

I get that recoverable alert all of the time.. I think that it's a BUG in 
Blitz.

 - Paul

> 
> Could someone please make me look stupid and tell me how I am killing the exec memory
> list! Oh and out of interest when I pass 4 as the required memory type to CachePCF
> it gurus straight away! So I AM doing something really dumb, it's just that after staring at the
> code until 4am, I just cannot see the wood for the trees
> 
> My Flawed Library... 
> 
> ;======================;
> ; PCF LIBRARY FOR BB2  ;
> ;======================;
> 
> #pcflib=40
> 
> !libheader{#pcflib,0,0,0,0}
> 
> !afunction{#long}
> !args{#string,#long}
> !libs{#doslib,#la6}
> !subs{_cachepcf,0,0}
> !name{"CachePCF","File name,Memory Type"}
> 
> !afunction{#long}
> !args{#string}
> !libs{#doslib,#la6}
> !subs{_pcfsize,0,0}
> !name{"PCFSize","File Name"}
> 
> !astatement
> !args{#long,#long}
> !libs
> !subs{_freepcfcache,0,0}
> !name{"FreePCFCache","Cache Start,Cache Length"}
> 
> !libfin
> 
> _cachepcf
>   MOVEM.l a3-a6,-(a7)
>   MOVE.l  #0,file_spot
>   MOVE.l  #0,unlock
>   MOVE.l  d0,file_name
>   MOVE.l  d1,memory_type
>   MOVE.l  d0,d1
>   MOVE.l  #-2,d2            ;shared lock, access read
>   JSR     -$54(a6)          ;Lock(name,type)(d1,d2)
>   CMP.l   #0,d0
>   BEQ     lock_error
>   MOVE.l  d0,file_lock
>   MOVE.l  #$e0,d0
>   MOVE.l  #0,d1
>   ALibJsr $c002             ;Allocate memory for a file
>   BEQ     ma_error1
>   MOVE.l  d0,file_info
>   MOVE.l  file_lock,d1
>   MOVE.l  d0,d2
>   JSR     -$66(a6)          ;Examine(lock,info buffer)(d1,d2)
>   BEQ     examine_error
>   MOVE.l  file_info,a0
>   MOVE.l  $7c(a0),d0        ;How long is the file
>   MOVE.l  d0,file_size
>   MOVE.l  memory_type,d1    ;Ready to allocate all memory
>   ALibJsr $c002
>   BEQ     ma_error2
>   MOVE.l  d0,file_spot      ;store the address
>   MOVE.l  file_lock,d1
>   JSR     -$17a(a6)         ;OpenFromLock(lock)(d1)
>   MOVE.l  d0,file_hand      ;our new handle for the file
>   CMP.l   #0,d0
>   BNE     continue          ;Open OK no need to unlock
> 
> file_error:
>   MOVE.l  file_spot,a1      ;could not open file, need to free memory
>   MOVE.l  file_size,d0      ;then the lock
>   ALibJsr $c003
>   MOVE.l  #0,file_spot      ;no memory carried over
> 
>   BRA     ma_error2         ;Carry on as if no memory was allocated
> 
> 
> continue:
>   MOVE.l  #1,unlock         ;no need to unlock now
>   MOVE.l  d0,d1
>   MOVE.l  file_spot,d2
>   MOVE.l  file_size,d3
>   JSR     -$2a(a6)          ;Read(file,buffer,length)(d1,d2,d3)
>   MOVE.l  d0,read_error     ;save any error number
> 
>                             ;Everything went OK free the file handle
> 
>   MOVE.l  file_hand,d1      ;start tidying up
>   JSR     -$24(a6)          ;Close(file)(d1)
>   MOVE.l  read_error,d0     ;now lets check the read was OK
>   CMP.l   #-1,d0
>   BNE     ma_error2         ;There was NO ERROR in reading
> 
>                             ;AN ERROR MUST FREE MEMORY
>   MOVE.l  file_spot,a1      ;could not read file, need to free memory
>   MOVE.l  file_size,d0      ;then the lock
>   ALibJsr $c003
>   MOVE.l  #0,file_spot      ;no memory carried over
> 
> ma_error2:                  ;Unable to allocate memory for file
>                             ;Nothing to do but move on
> 
> examine_error:              ;Could not look at lock but still must free memory
>   MOVE.l  file_info,a1
>   MOVE.l  #$e0,d0
>   ALibJsr $c003             ;Free file info memory
> 
> ma_error1:                  ;Could not even get memory for file info!
>                             ;But must free the lock IF it was not opened
>   MOVE.l  unlock,d0
>   CMP.l   #1,d0
>   BEQ     lock_error        ;no need to relinquish lock
>   MOVE.l  file_lock,d1
>   JSR     -$5a(a6)          ;Unlock(Lock)(d1)
> 
> lock_error:                 ;No lock no bloody nothing!
> 
> ok:
>   MOVEM.l (a7)+,a3-a6
>   MOVE.l  file_spot,d0      ;every thing went OK! give the user the pointer to the cache
>   RTS
> 
> ;RETURN THE SIZE OF A FILE
> 
> _pcfsize
>   MOVEM.l a3-a6,-(a7)
>   MOVE.l  d0,d1
>   MOVE.l  #-2,d2            ;shared lock, access read
>   JSR     -$54(a6)          ;Lock(name,type)(d1,d2)
>   CMP.l   #0,d0
>   BEQ     size_lock_error
>   MOVE.l  d0,file_lock
>   MOVE.l  #0,file_size
>   MOVE.l  #$e0,d0
>   MOVE.l  #0,d1
>   ALibJsr $c002             ;Allocate memory for a file
>   BEQ     size_ma_error1
>   MOVE.l  d0,file_info
>   MOVE.l  file_lock,d1
>   MOVE.l  d0,d2
>   JSR     -$66(a6)          ;Examine(lock,info buffer)(d1,d2)
>   BEQ     size_examine_error
>   MOVE.l  file_info,a0
>   MOVE.l  $7c(a0),d0        ;How long is the file
>   MOVE.l  d0,file_size
> 
> size_examine_error:         ;Could not look at lock but still must free memory
>   MOVE.l  file_info,a1
>   MOVE.l  #$e0,d0
>   ALibJsr $c003             ;Free file info memory
> 
> size_ma_error1:             ;Could not even get memory for file info!
>                             ;But must free the lock IF it was not opened
>   MOVE.l  file_lock,d1
>   JSR     -$5a(a6)          ;Unlock(Lock)(d1)
> 
> size_lock_error:            ;No lock no bloody nothing!
> 
> size_ok:
>   MOVEM.l (a7)+,a3-a6
>   MOVE.l  file_size,d0      ;every thing went OK!
>   RTS
> 
> 
> 
> file_name: Dc.l 0
> file_lock: Dc.l 0
> file_info: Dc.l 0
> file_size: Dc.l 0
> file_spot: Dc.l 0
> file_hand: Dc.l 0
> unlock:    Dc.l 0
> memory_type: Dc.l 0
> read_error: Dc.l 0
> 
> _freepcfcache:
>   MOVEA.l d0,a1
>   MOVE.l  d1,d0
>   ALibJsr $c003
>   RTS
> 
> size_ma_error1:             ;Could not even get memory for file info!
>                             ;But must free the lock IF it was not opened
>   MOVE.l  file_lock,d1
>   JSR     -$5a(a6)          ;Unlock(Lock)(d1)
> 
> size_lock_error:            ;No lock no bloody nothing!
> 
> size_ok:
>   MOVEM.l (a7)+,a3-a6
>   MOVE.l  file_size,d0      ;every thing went OK!
>   RTS
> 
> 
> 
> file_name: Dc.l 0
> file_lock: Dc.l 0
> file_info: Dc.l 0
> file_size: Dc.l 0
> file_spot: Dc.l 0
> file_hand: Dc.l 0
> unlock:    Dc.l 0
> memory_type: Dc.l 0
> read_error: Dc.l 0
> 
> _freepcfcache:
>   MOVEA.l d0,a1
>   MOVE.l  d1,d0
>   ALibJsr $c003
>   RTS
> 
> 

----------------------------------------------------------------------------
Paul Reece, Student & Network Assistant                               \\\///
Claremont College - Tasmania, Australia                               d oo b   
                                                                      | __ |
[email-masked], [email-masked]    \__/
----------------------------------------------------------------------------
The opinions expressed herein are my own and not those of Claremont College!
----------------------------------------------------------------------------